class MiscTests extends CloudToolsBaseTests{
	
	def cloudToolsService;
	
	void setUp(){
		super.setUp()
		executeGrailsCommand("cloud-tools-deploy", null)
	}
	
	void tearDown(){
		executeGrailsCommand("cloud-tools-stop", null)
	}
	
	void testMisc(){
		//test bad enable-brb
		def result = executeGrailsCommand("cloud-tools-enable-brb", null)
		println "Err: ${result.getErrOut()}"
		assertExitValue(0, result);
	    assertStdErr('You did not specify a brb page', result);
		
		//test enable-brb
		result = executeGrailsCommand("-Dcloudtools.brb.page=index.html cloud-tools-enable-brb", null)
		assertExitValue(0, result);
	    assertStdOut("Done enabling brb page", result);
	
		//test disable-brb
		result = executeGrailsCommand("-Dcloudtools.brb.page=/ cloud-tools-disable-brb", null)
		assertExitValue(0, result);
	    assertStdOut("Done disabling the brb page", result);
	
		//test list
		result = executeGrailsCommand("cloud-tools-list", null)
		assertExitValue(0, result);
	    assertStdOut("Done listing clusters", result);
	
		//test restart-apache
		result = executeGrailsCommand("cloud-tools-restart-apache", null)
		assertExitValue(0, result);
	    assertStdOut("Done restarting apache", result);
	
		//test verify
		result = executeGrailsCommand("cloud-tools-verify", null)
		assertExitValue(0, result);
	    assertStdOut("Verification complete", result);
		
		//this db-save is used to setup a file on S3 for the next test
		result = executeGrailsCommand("-Dcloudtools.s3.path=${cloudToolsService.getAccessKey()}-cloudtoolstest/backup.sql cloud-tools-db-save", null)
		
		//test update-war
		result = executeGrailsCommand("-Dcloudtools.s3.path=${cloudToolsService.getAccessKey()}-cloudtoolstest/backup.sql -Dcloudtools.path=explodedWar/cloudtools/WEB-INF/applicationContext.xml cloud-tools-update-war", null)
		assertExitValue(0, result);
	    assertStdOut("War updated", result);
	
		//test bad update-war
		result = executeGrailsCommand("cloud-tools-update-war", null)
		assertExitValue(0, result);
	    assertStdErr('You need to specify cloudtools.s3.path and cloudtools.path', result);
	
		//test bad curl
		result = executeGrailsCommand("cloud-tools-curl", null)
		assertExitValue(0, result);
	    assertStdErr("You must specify cloudtools.curl.path", result);
	
		//test curl
		result = executeGrailsCommand("-Dcloudtools.curl.path=/ cloud-tools-curl", null)
		assertExitValue(0, result);
	    assertStdOut("Finished with curl on", result);
	
		//test db-recreate (doesn't work yet)
		//result = executeGrailsCommand("cloud-tools-db-recreate", null)
		//assertExitValue(0, result);
	    //assertStdOut("Finished with db-recreate", result);
	
		//test init-lb-pool
		//result = executeGrailsCommand("cloud-tools-init-lb-pool", null)
		//assertExitValue(0, result);
	    //assertStdOut("Done with Init LB Pool", result);
	
		//test bad sql
		result = executeGrailsCommand("cloud-tools-sql", null)
		assertExitValue(0, result);
	    assertStdErr("You specify cloudtools.sql.script", result);
	
		//test sql
		new File("explodedWar/test.sql").withWriter{out -> out << "select NOW()"}
		result = executeGrailsCommand("-Dcloudtools.sql.script=./explodedWar/test.sql cloud-tools-sql", null)
		assertExitValue(0, result);
	    assertStdOut("Finished with sql", result);
	}
}